<?php
namespace Home\Controller;
use Think\Controller;
use Think\Page;

/*
* 特色服务 & 优惠精选
*/
class ArticleController extends CommonController {
  private $article_model;

  public function _initialize(){
    parent::_initialize();

    $this->article_model = M('Article');
  }

	//优惠精选列表
	public function index(){
    $template_params['category'] = L('nav_discount');
    
	    $count      = $this->article_model-> where("category_id=2")->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
			
		$articles = $this->article_model->where("category_id=2")->limit($Page->firstRow.','.$Page->listRows)->order('created_at desc')->select();
		foreach ($articles as $i => $article){
			$articles[$i] = $this->check_EN_ZH($article);
		}
		$this->assign('page',$show);
		
    $this->assign('articles',$articles);
    $this->assign('template_params',$template_params);
    $this->display('Article/index');
	}

  public function news(){
    $template_params['category'] = L('news');
    
    	$count      = $this->article_model-> where("category_id=6")->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
    $articles = $this->article_model->where("category_id=6")->limit($Page->firstRow.','.$Page->listRows)->order('created_at desc')->select();
  	foreach ($articles as $i => $article){
			$articles[$i] = $this->check_EN_ZH($article);
		}
    $this->assign('page',$show);
    $this->assign('articles',$articles);
    $this->assign('template_params',$template_params);
    $this->display('Article/index');
  }

  //优惠精选文章详细
  public function show(){
    $article = $this->article_model->find(I('get.id',0));
	  $article = $this->check_EN_ZH($article);
    $template_params['category'] = L('news');
    
    $this->assign('article',$article);
    $this->assign('template_params',$template_params);
    $this->display('Article/show');
  }

  //特色服务-》休闲出行
	public function xiuxian(){
    $template_params['action'] = __FUNCTION__;
    $template_params['banner'] = __FUNCTION__;
		$articles = $this->article_model->where("category_id=3")->limit(3)->order('created_at desc')->select();
		foreach ($articles as $i => $article){
			$articles[$i] = $this->check_EN_ZH($article);
		}
		

    $this->assign('articles',$articles);
    $this->assign('template_params',$template_params);
    $this->display('Article/img_list');
	}

	//特色服务-》修身养性
	public function xiushen(){
    $template_params['action'] = __FUNCTION__;
    $template_params['banner'] = __FUNCTION__;
		$articles = $this->article_model->where("category_id=5")->limit(3)->order('created_at desc')->select();
		foreach ($articles as $i => $article){
			$articles[$i] = $this->check_EN_ZH($article);
		}

    $this->assign('articles',$articles);
    $this->assign('template_params',$template_params);
    $this->display('Article/img_list');
	}
}